package com.anyikang.volunteer.sos.volunteer.utils;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import com.anyikang.volunteer.sos.volunteer.R;

import org.json.JSONObject;

import okhttp3.Response;

import static com.lzy.okhttputils.interceptor.LoggerInterceptor.TAG;

/**
 * Created by xw.gao on 2017/6/16.
 *
 */


public class MyErrorDeal {

    public MyErrorDeal()
    {

    }

    static public void dealError(String msg, Context context)
    {
        if(msg.equals("该用户不存在"))
        {
            msg = context.getResources().getString(R.string.token_timeout); //登录超时
           //gxw- PageUtils.goLogin(context);
        }
        else if(msg.contains("您当前正在救援中,请完成后再接单"))
        {

        }
        else if(msg.contains("重新登陆"))
        {
          msg="登录已过时，请在设置里退出后，重新登录";
        }
        Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();
        return;
    }

    static public void dealHttpError(Response response, Context context)
    {
        try
        {
            if(response != null && response.code() == 500)
            {
                JSONObject groupListObj = new JSONObject(response.body().string());
                String msg = groupListObj.getString("message");
                dealError(msg,context);
            }
            else {

                Toast.makeText(context,"请求网络失败",Toast.LENGTH_SHORT).show();
            }

        }catch (Exception e1)
        {
            e1.printStackTrace();
        }
    }
}
